package com.aracky.common.vo;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author zengzhiping
 * @ClassName ResultPage
 * @Description 封装分页返回结果
 * @createTime 2022年05月13日
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PageObjectVO<T> implements Serializable {

    @ApiModelProperty("当前页")
    private Long page;

    @ApiModelProperty("每页数量")
    private Long size;

    @ApiModelProperty("总页数")
    private Long totalPage;

    @ApiModelProperty("总记录数")
    private Long totalCount;

    @ApiModelProperty("数据集")
    private Object data;

    public PageObjectVO(IPage<T> page) {
        this.page = page.getCurrent();
        this.size = page.getSize();
        this.totalPage = page.getPages();
        this.totalCount = page.getTotal();
        this.data = page.getRecords();
    }

    /**
     * 转换为page
     *
     * @param page
     * @param <T>
     * @return
     */
    public static <T> PageObjectVO<T> convertPage(IPage<T> page) {
        return new PageObjectVO(page);
    }

}
